/*****************************************************************************

File:   otkSessionUtils.java

Date          Build     Author        Version    Comments
18-Sep-12    P-20-14    dshah          $$1        Created
12-Oct-12    P-20-14    dshah          $$2        Updated
20-mar-15 P-30-05 gshmelev $$3  called GetCurrentSession

****************************************************************************/

/* 
 
 Utilites for wfcWSession
  
*/

package com.ptc.otkjavaexamples;
 
import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSession.*;

 

class otkSessionUtils extends DefaultUICommandActionListener
{
    
    
    
    public otkSessionUtils()
    {
    }
    
    public void OnCommand()
    {
	try
	    {
		FileWriter file1 = new FileWriter ("DumpSessionInfo.inf");
		BufferedWriter InfoFile = new BufferedWriter(file1);
		
		FileWriter file2 = new FileWriter ("DumpSessionInfo.log");
		BufferedWriter LogFile = new BufferedWriter(file2);
		
		Session session = pfcSession.GetCurrentSession ();
		WSession wSession = (WSession)(session);

		int status =  OtkUtilWriteSessionInfo ( wSession,
							InfoFile,
							LogFile,
							3 );
		InfoFile.close();
		LogFile.close();

		Double Xoffset = new Double(0);
		Double Yoffset = new Double(0);
		Integer rows = new Integer(0);
		Integer columns = new Integer(0);
			
		wSession.DisplayInformationWindow("DumpSessionInfo.inf", Xoffset, Yoffset, rows, columns);
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
    }
    
    int OtkUtilWriteSessionInfo (
				 WSession          wSession, // input
				 BufferedWriter    InfoFile, // input
				 BufferedWriter    LogFile,  // input
				 int               level )   // input - level details of info to be written
	//------------------------------------------------------------------------------
	// Purpose: Writes Session Information
	//------------------------------------------------------------------------------
    {
	String file_buff; 
	
	if( wSession == null)
	    return -1;
	
	try
	    {
		InfoFile.write("==============================");
		InfoFile.newLine();
		InfoFile.write("-       Session Info         -");
		InfoFile.newLine();
		InfoFile.write("==============================");
		InfoFile.newLine();
		
		int wNumericVersion = wSession.GetReleaseNumericVersion ();
		InfoFile.write("\t - integer major version number of the Creo executable : " + wNumericVersion);
		InfoFile.newLine();
		
		String wDateCode = wSession.GetDisplayDateCode ();
		InfoFile.write("\t - customer visible date code of the Creo executable : " + wDateCode);
		InfoFile.newLine();
		
		String wCurrentDir = wSession.GetCurrentDirectory ();
		InfoFile.write("\t - Curent Directory : " + wCurrentDir);
		InfoFile.newLine();
		
		String wCurrentWS = wSession.GetCurrentWS  ();
		
		if ( wCurrentWS != null )
		    {
			InfoFile.write("\t - Curent Workspace : " + wCurrentWS);
			InfoFile.newLine();
		    }
		
		Model wCurrentModel = wSession.GetCurrentModel();
		
		if ( wCurrentModel == null )
		    {
			InfoFile.write("\t - There is no Current Model. ");
			InfoFile.newLine();
		    }
		else
		    {
			String wCurrentModelName = wCurrentModel.GetFileName();
			
			InfoFile.write("\t - Curent Model Name : " + wCurrentModelName);
			InfoFile.newLine();
		    }
		
		Model wActiveModel = wSession.GetActiveModel();
		
		if ( wActiveModel == null )
		    {
			InfoFile.write("\t - There is no Active Model. ");
			InfoFile.newLine();
		    }
		else
		    {
			String wActiveModelName = wActiveModel.GetFileName();
			
			InfoFile.write("\t - Active Model Name : " + wActiveModelName);
			InfoFile.newLine();
		    }
		

		return 0;
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	
	return 0;
    }
    
};






